package com.blogsystem.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blogsystem.entity.Category;
import com.blogsystem.mapper.CategoryMapper;
import com.blogsystem.service.CategoryService;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

@Service
public class CategoryServiceImpl extends ServiceImpl<CategoryMapper, Category> implements CategoryService {

    public Category getByName(String categoryName) {
        // 使用 MyBatis-Plus 的 QueryWrapper 查询
        Category category = getOne(query().eq("name", categoryName));
        if (category != null) {
            return category;
        }
        return null;
    }

    public Page<Category> pageCategories(Page<Category> page, QueryWrapper<Category> queryWrapper) {
        return baseMapper.selectPage(page, queryWrapper);
    }
}